<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检测文件的 MIME 类型</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.finfo-set-flags.html">« finfo_set_flags</a></li>
      <li style="float: right;"><a href="class.finfo.html">finfo »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.fileinfo.html">Fileinfo 函数</a></li>
    <li>检测文件的 MIME 类型</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mime-content-type" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mime_content_type</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mime_content_type</span> &mdash; <span class="dc-title">检测文件的 MIME 类型</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mime-content-type-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mime_content_type</strong></span>(<span class="methodparam"><span class="type"><span class="type">resource</span>|<span class="type">string</span></span> <code class="parameter">$filename</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
    返回通过使用  <var class="filename">magic.mime</var> 
    检测到的文件 MIME 类型。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mime-content-type-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       要检测的文件名。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mime-content-type-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回文件的 MIME 内容类型，例如
   <code class="literal">text/plain</code> 或 <code class="literal">application/octet-stream</code>。 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-function.mime-content-type-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
失败时抛出 <strong><code>E_WARNING</code></strong> 警告。
</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mime-content-type-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2137">
    <p><strong>示例 #1 <span class="function"><strong>mime_content_type()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">mime_content_type</span><span style="color: #007700">(</span><span style="color: #DD0000">'php.gif'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">mime_content_type</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.php'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
image/gif
text/plain
</pre></div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.mime-content-type-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="finfo.file.html" class="function" rel="rdfs-seeAlso">finfo_file()</a> - 别名 finfo_file()</span></li>
    <li class="member"><span class="function"><a href="finfo.buffer.html" class="function" rel="rdfs-seeAlso">finfo_buffer()</a> - 别名 finfo_buffer()</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>